package aufgabenserie_2;

import java.math.BigInteger;
import java.util.Random;

public class Starter {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		AliceORBob alice = new AliceORBob();
		AliceORBob bob  = new AliceORBob();
		long start = 0;
		int numBits = 64;
		BigInteger g; 
		BigInteger n;
		
		//calculate a n and g
		do {
			n = BigInteger.probablePrime(numBits,  new Random() );
		} while (n.isProbablePrime(100) == false);
		
		do {
			g = new BigInteger((int) (numBits*Math.random()), new Random() );			
		} while (n.compareTo( g.subtract( new BigInteger("2") )) < 0 && g.compareTo(new BigInteger("2")) < 0);
		
		System.out.println("Try 1 - without square and multiply");
		start = System.currentTimeMillis();
		alice.startCommunication(g, n, bob, false);
		System.out.println(System.currentTimeMillis()- start + " ms\n\n-----------------------");
		
		System.out.println("Try 2 - with square and multiply");
		start = System.currentTimeMillis();
		alice.startCommunication(g, n, bob, true);
		System.out.println(System.currentTimeMillis()- start + " ms\n-----------------------");
		
//		testSqareMultiple();

	}

	private static void testSqareMultipy() {
		BigInteger e = new BigInteger("54");
		Integer x = 554;
		BigInteger n = new BigInteger("5000");
		
		BigInteger b = e.pow(x).mod(n);
		System.out.println("e.pow: "+b);
		
		BigInteger a = AliceORBob.squareAndMultiply(e, new BigInteger(x.toString()), n);
		System.out.println("squareAndMultiply: "+a);
	}

}
